package com.um.springboot.starter.controller;

import com.um.springboot.starter.annotation.ActionLogRequired;
import com.um.springboot.starter.utils.VerifyCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 验证码生成连接
 *
 * @author 邓南辉
 * @date 2020/3/6
 * @copyright 广州优匠科技有限公司
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/verify")
@ActionLogRequired
public class VerifyCodeController {

    @RequestMapping("/random_code")
    public void createImg(HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            response.setContentType("image/jpeg");//设置相应类型,告诉浏览器输出的内容为图片
            response.setHeader("Pragma", "No-cache");//设置响应头信息，告诉浏览器不要缓存此内容
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expire", 0);

            VerifyCode verifyCode = new VerifyCode();
            verifyCode.getRandcode(request, response);//输出验证码图片
        } catch (Exception e) {
            log.error("获取验证码异常：", e);
        }
    }
}
